package com.ophiux.cs.api.config;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

import com.ophiux.cs.api.OphiuxCSOnlineService;

/**
 * 说明：cxf发布webservice配置<br>
 * <h1>创 建 人: hehailong<br></h1>
 * 创建日期: 2018年8月4日 下午9:58:12<br>
 */
@Configuration
public class WebServiceConfig {
	@Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public OphiuxCSOnlineService ophiuxCSOnlineService() {
        return new OphiuxCSOnlineService();
    }

    /**
     * 自定义servlet的访问
     */
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/OphiuxCSOnlineServiceService/ws/*");
        bean.setLoadOnStartup(0);
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return bean;
    }

    /** JAX-WS **/
    @Bean
    public EndpointImpl endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), ophiuxCSOnlineService());
        endpoint.publish("/service");
        return endpoint;
    }

}
